<style lang="less">
  .el-form-item {
    margin: 0px 20px 15px 20px;
  }

  .el-collapse {
    border: 0px;
    .el-collapse-item {
      border: 1px solid #dfe6ec;
      margin-bottom: 15px;
      .el-collapse-item__header {
        font-weight: bold;
        .el-collapse-item__header__arrow {
          display: none;
        }
      }
      .el-collapse-item__content {
        padding-bottom: 0px;
      }
      .el-collapse-item__wrap {
        border-bottom: 0px;
      }
    }
  }
</style>

<template>
  <el-form ref="form" label-position="left" :rules="rules" :model="form" label-width="80px">
    <el-collapse accordion value="1">
      <el-collapse-item title="一致性" name="1">
        <el-form-item label="别名" prop="alias">
          <el-input  v-model="form.alias" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input  v-model="form.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input  v-model="form.password" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="邮件" prop="email">
          <el-input  v-model="form.email" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="手机" prop="phone">
          <el-input  v-model="form.phone" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="生日" prop="birthday">
          <el-date-picker  type="date" placeholder="选择日期" v-model="form.birthday"></el-date-picker>
        </el-form-item>
      </el-collapse-item>
    </el-collapse>
    <div style="margin-top: 5px;text-align: right">
      <el-button @click="$router.push($route.meta.parent)">取 消</el-button>
      <el-button type="primary" :loading="submitLoading" @click="handleSubmit">确 定</el-button>
    </div>
  </el-form>
</template>

<script>
import { savePartners, getPartner } from '../../api/api';

export default{
  data () {
    return {
      submitLoading: false,
      form: {
        'id': null,
        'password': null,
        'alias': null,
        'email': null,
        'name': null,
        'phone': null,
        'sex': null,
        'status': null,
        'type': null,
        'birthday': null
      },
      rules: {
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'},
          {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}
        ],
        alias: [
          {required: true, message: '请输入别名', trigger: 'blur'},
          {min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur'}
        ],
        email: [
          {required: true, message: '请输入邮件', trigger: 'blur'},
          {min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur'}
        ],
        phone: [
          {required: true, message: '请输入手机号码', trigger: 'blur'}
        ]
      }
    };
  },
  methods: {
    handleSubmit () {
      // 表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.submitLoading = true;
          savePartners('xxx', this.form).then((res) => {
            this.submitLoading = false;
            if (res.data.successFlg === true) {
              this.$router.push(this.$route.meta.parent);
            } else {
              this.$message.error(res.data.errorMsg);
            }
          }).catch(function (error) {
            console.log(error);
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  },
  mounted () {
    if (this.$route.params.id !== undefined) {
      getPartner(this.$route.params.id).then((res) => {
        if (res.data.successFlg === true) {
          res.data.obj.profitSummary = null;
          this.form = Object.assign({}, res.data.obj);
        } else {
          this.$message.error(res.data.errorMsg);
        }
      }).catch((error) => {
        console.log(error);
      });
    }
  }
};
</script>
